package com.wanxi.servlet;

import com.wanxi.model.CompanyModel;
import com.wanxi.model.NavModel;
import com.wanxi.model.NewsModel;
import com.wanxi.service.CompanyService;
import com.wanxi.service.NavService;
import com.wanxi.service.NewService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Li
 * @Date 2023/4/27 21:48
 */
@WebServlet("/new")
public class NewsCenterServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //        乱码解决
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        接收前端数据
//        封装model
//        调用服务层
        CompanyService companyService = new CompanyService();
        NavService navservice = new NavService();
        NewService newService =new NewService();

//        返回给前端
        CompanyModel companyModel = companyService.getCompany();
        List<NavModel> NavModelList = navservice.getNav();
        List<NavModel> NavModelList1 = navservice.getNav1();
        List<NewsModel> newsModelLists = newService.getNews();
        List<NewsModel> newsModelTitles = newService.getNewTitles();
        req.setAttribute("company",companyModel);
        req.setAttribute("nav",NavModelList);
        req.setAttribute("nav1",NavModelList1);
        req.setAttribute("newsModelLists",newsModelLists);
        req.setAttribute("newsModelTitles",newsModelTitles);
        req.getRequestDispatcher("/jsp/newscenter.jsp").forward(req,resp);
    }
}
